﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using UnityEngine;

public class AttackVo
{
    public int attackType;

    public Boolean win;

    public string sceneID;

    public List<FightInfoVo> fightVos;

    public List<FightPetInfoVo> fightPetVos;

    public List<BoutVo> boutVos;

    public string configID;

    public string leftPlayer;

    public string rightPlayer;

    public string leftLevel;

    public string rightLevel;

    public string leftModel;

    public string rightModel;

    public string leftClothemodel;

    public string rightClothemodel;

    public string leftTotalspeed;

    public string rightTotalspeed;


    public AttackVo(XmlDocument xmlDoc)
    {
        try
        {
            XmlNodeList nodeList = xmlDoc.SelectNodes("FightProcess");

            XmlNode node = nodeList[0];
            int count = node.Attributes.Count;

            XmlAttributeCollection attributeArr = node.Attributes;

            configID = attributeArr["FightingGUID"].Value;

            attackType = int.Parse(attributeArr["FightType"].Value);

            //leftPlayer = attributeArr["LeftName"].Value;

            //rightPlayer = attributeArr["RightName"].Value;

           // leftLevel = attributeArr["LeftLevel"].Value;

           // rightLevel = attributeArr["RightLevel"].Value;

            //leftModel = attributeArr["LeftModel"].Value;

           // rightModel = attributeArr["RightModel"].Value; ;

            //leftClothemodel = attributeArr["LeftClothModel"].Value;

           // rightClothemodel = attributeArr["RightClothModel"].Value;

            //leftTotalspeed = attributeArr["LeftTotalSpeed"].Value;

            //rightTotalspeed = attributeArr["RightTotalSpeed"].Value;

            fightVos = new List<FightInfoVo>();

            XmlNodeList nodeList2 = xmlDoc.SelectNodes("FightProcess/FightInfo");
            XmlNode node2 = nodeList2[0];

            sceneID = node2.Attributes["sceneID"].Value;

            int count2 = node2.ChildNodes.Count;
            XmlNodeList childNode1 = node2.ChildNodes;
            for (int j = 0; j < count2; j++)
            {
                if (childNode1[j].Name == "Pos")
                {
                    fightVos.Add(new FightInfoVo(childNode1[j].Attributes));
                }
                else if (childNode1[j].Name == "Pet")
                {
                    fightPetVos.Add(new FightPetInfoVo(childNode1[j].Attributes));
                }
                
            }

            boutVos = new List<BoutVo>();
            BoutVo boutVo;
            XmlNodeList nodeList3 = xmlDoc.SelectNodes("FightProcess/Bout");
            for (int m = 0; m < nodeList3.Count; m++)
            {
                XmlNode node3 = nodeList3[m];
                boutVo = new BoutVo(int.Parse(node3.Attributes["count"].Value));
                boutVos.Add(boutVo);

                XmlNodeList nodeList4 = node3.SelectNodes("BoutInfo");
                int count6 = nodeList4[0].ChildNodes.Count;
                XmlNodeList childNode2 = nodeList4[0].ChildNodes;
                for (int j = 0; j < count6; j++)
                {
                    XmlAttributeCollection attributeArr2 = childNode2[j].Attributes;
                    boutVo.boutInfoVos.Add(new BoutInfo(attributeArr2["pos"].Value, attributeArr2["state"].Value,attributeArr2["hp"].Value,
                        attributeArr2["mor"].Value, attributeArr2["maxhp"].Value,
                        attributeArr2["buffer"].Value));
                }

                XmlNodeList nodeList6 = node3.SelectNodes("Flow");
                for (int n = 0; n < nodeList6.Count; n++)
                {
                    XmlNodeList childNode4 = nodeList6[n].ChildNodes;

                    XmlAttributeCollection attributeArr3 = nodeList6[n].Attributes;
                    boutVo.flowVos.Add(new FlowVo(attributeArr3["pos"].Value, attributeArr3["state"].Value, attributeArr3["skill"].Value,
                        attributeArr3["ackType"].Value,attributeArr3["ackMode"].Value,attributeArr3["scope"].Value,
						attributeArr3["targetpos"].Value, attributeArr3["mor"].Value, attributeArr3["buffer"].Value, childNode4));
                }

            }


        }
        catch (System.Exception ex)
        {
            Debug.Log("AttackVo " + ex.ToString());
        }




    }
}